﻿using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure.Interception;
using EntityFramework6.Services.Interceptors;

namespace EntityFramework6.Services.Data
{
    public partial class BookContext : DbContext
    {
        private const string connectionString = @"data source=.\SQLEXPRESS;Integrated Security=True; database=EF6Samples;MultipleActiveResultSets=True";

        public BookContext()
            : base(connectionString)
        {
            // log the SQLs to console
            this.Database.Log = LogDetails;
            this.Configuration.LazyLoadingEnabled = false;
        }

        // Registr the custom interceptor
        static BookContext()
        {
            DbInterception.Add(new EFCustomIntercptor());
        }

        public virtual DbSet<Book> Books { get; set; }
        public virtual DbSet<Author> Authors { get; set; }
        public virtual DbSet<Publisher> Publishers { get; set; }

        private void LogDetails(string efLogActiviey)
        {
            Console.WriteLine(efLogActiviey);
        }
    }

   
}
